package org.classdef.analyzer.info.attribute;

import java.util.ArrayList;
import java.util.List;

import org.classdef.analyzer.info.ClassDef;

/**
 * 
 * 属性池
 *
 */
public class AttributePool {
	
	private List<AttributeInfo> infos = new ArrayList<AttributeInfo>();
	
	private ClassDef def;
	
	public void add(short attributeNameIndex, int attributeLength, byte[] info){
		AttributeInfo attributeInfo = new AttributeInfo(attributeNameIndex, attributeLength, info);
		attributeInfo.def = def;
		infos.add(attributeInfo);
	}
	
	/**
	 * @return infos
	 */
	public List<AttributeInfo> getInfos() {
		return infos;
	}

	public ClassDef getDef() {
		return def;
	}

	public void setDef(ClassDef def) {
		this.def = def;
	}

	/* （非 Javadoc）
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("[");
		for (AttributeInfo info : infos) {
			sb.append(info).append(", ");
		}
		if(sb.length() > 1){
			sb.setLength(sb.length() - 1);
		}
		sb.append("]");
		return sb.toString();
	}
}
